package homework5.test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.nio.charset.Charset;


/**
 * @author fengq
 */
public class DatagramSocketTest1 {
    public static void main(String[] args) throws IOException {
        byte[] buf=new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(buf, 1024);
        DatagramSocket datagramSocket = new DatagramSocket(8800);
        datagramSocket.receive(datagramPacket);
        String mess1=new String(datagramPacket.getData(),0,datagramPacket.getLength(), Charset.forName("UTF-8"));
        System.out.println(datagramPacket.getAddress().getHostAddress()+"说："+mess1);
        String mess2="你好，我在，请咨询";
        System.out.println("我说："+mess2);
        datagramPacket.setData(mess2.getBytes());
        datagramSocket.send(datagramPacket);
    }
}
